#pragma once
#include"Protocol.hpp"
#include<iostream>
class Cal{
    public:
        Response Execute(const Request& req){
            Response res=Response(0,0);
            int x=req.getX();
            int y=req.getY();
            char oper=req.getOper();
            int result=0;
            int code=0;
            switch(oper){
                case '+':
                    result=x+y;
                    break;
                case '-':
                    result=x-y;
                    break;
                case '*':
                    result=x*y;
                    break;
                case '/':
                    if(y==0){
                        code=-1;
                        result=0;
                    }else{
                        result=x/y;
                    }
                    break;
                case '%':
                    if(y==0){
                        code=-1;//规定-1为除零错误
                        result=0;
                    }else{
                        result=x%y;
                    }
                    break;
                default:
                    code=404;//404表示非法操作符
                    result=0;
                    break;
            }
            res.setCode(code);
            res.setResult(result);
            return res;
        }
};